<?php
class LinkModel extends ModelBase
{
	protected static $_tableName = 'links';
	
	public static function add($typeid, $name, $url, $logo, $priority)
	{
		$data = array(
			'typeid'	=> $typeid,
			'name'	=> $name,
			'url'	=> $url,
			'logo'	=> $logo,
			'priority'	=> $priority,
		);
		return self::queryInsert(self::$_tableName, $data);
	}
	
	public static function update($id, $data)
	{
		return self::queryUpdate(self::$_tableName, $data, "id={$id}");
	}
	
	public static function get($id)
	{
		return self::querySelectSingle(self::$_tableName, array('*'), "id={$id}");
	}
	
	public static function del($id)
	{
		return self::queryDelete(self::$_tableName, "id={$id}");
	}
	
	public static function getCount($where='')
	{
		$data = self::querySelectSingle(self::$_tableName, array('count(0) num'), $where);
		return isset($data['num']) ? intval($data['num']) : 0; 
	}
	
	public static function getList($where='', $page=0, $pageSize=40)
	{
		if ($page){
			$start = ($page-1) * $pageSize;
			return self::querySelect(self::$_tableName, array('*'), $where, 'priority asc', $start, $pageSize);
		}else{
			return self::querySelect(self::$_tableName, array('*'), $where, 'priority asc');
		}
		
	}
}